<template>
	<div class="order-list-container">
		<div class="olc-head">
			<span>订单编号：{{ ibase.number }}</span>
			<span>{{ buildStateText }}</span>
		</div>
		<order-list-item :ibase="ibase" :dataset="dataset" type="shop" />
		<div class="olc-price" v-if="ibase.amount">
			<p>预估价格：<span>￥</span><span>{{ parseFloat(ibase.amount).toFixed(2) }}</span></p>
			<p v-if="ibase.protect==1" class="tip-footer">(价格保护已开启)</p>
		</div>
		<div :class="{'olc-footer': !stylePlan, 'olc-footer-qun': stylePlan}">
            <template v-if="textType == 'waitOut'">
                <van-button @click="$router.push('/reservoirManagement/order-details?ordernumber='+ibase.number)"
                    slot="button" size="small" type="primary" class="normal-diy-button" round>查看详情</van-button>
                <van-button @click="eventClickOrderOut" slot="button" size="small" type="primary" class="order-assist-button" round>出库</van-button>
            </template>
			<van-button v-else-if="textType!='wait' && textType!='warehousing'" slot="button" size="small" @click="eventClickOrderDetail" type="primary" class="normal-diy-button" round>
				查看详情
			</van-button>
			<van-button v-if="textType == 'confirm'" @click="eventClickOrderConfirm" slot="button" size="small" type="primary" class="order-assist-button" round>确认
			</van-button>
			<van-button v-if="textType == 'wait'" @click="$router.push('/shop/order-details?ordernumber='+ibase.number)" slot="button" size="small" type="primary" class="normal-diy-button" round>入库</van-button>
			<van-button v-if="textType == 'warehousing'" @click="$router.push('/shop/order-details?ordernumber='+ibase.number)" slot="button" size="small" type="primary" class="normal-diy-button" round>查看详情
			</van-button>
			<van-button v-if="textType == 'collectGR'" @click="$router.push('/shop/order-details?ordernumber='+ibase.number)" slot="button" size="small" type="primary" class="normal-diy-button" round>收取
			</van-button>
		</div>
	</div>
</template>

<script>
	import { Button, Dialog } from 'vant';

	import OrderListItem from './normal-list-base.vue';

	export default {
		components: {
			[Button.name]: Button,
			OrderListItem
		},
		props: ['textType', 'ibase', 'dataset'],
		computed: {
			buildStateText() {
				var stateText = '';
				switch (this.textType) {
					case 'collect':
						stateText = '待收取';
						break;
					case 'confirm':
					case 'accounting-confirm':
						stateText = '待确认';
						break;
					case 'complete':
						stateText = '已完成';
						break;
					case 'cancel':
						stateText = '已取消';
						break;
					case 'wait':
						stateText = '待入库';
						break;
					case 'warehousing':
						stateText = '已入库';
						break;
					case 'accounting-un-confirm':
						stateText = '已确认';
						break;
				}
				return stateText;
			},
			buildHostButtonText() {
				var buttonText = '';
				switch (this.textType) {
					case 'collect':
						buttonText = '查看详情';
						break;
					case 'confirm':
						buttonText = '确认收取';
						break;
					case 'complete':
						buttonText = '查看详情';
						break;
					case 'cancel':
						buttonText = '查看详情';
						break;
					case 'accounting-confirm':
						buttonText = '确认';
						break;
					case 'accounting-un-confirm':
						buttonText = '查看详情';
						break;

				}
				return buttonText;
			},
			stylePlan() {
				return this.ibase.style ? true : false;
			}
		},
		mounted() {
		},
		methods: {
			eventClickOrderDetail() {
				this.$router.push({
					path: '/shop/order-details',
					query: {
                        ordernumber: this.ibase.number
					}
				})
			},
			eventClickOrderConfirm() {
				var url = '/api/home/order/confirm';
				var param = {
					ordernumber: this.ibase.number,
					token: this.$store.state.options.user.token
				};
				this.$util.postRequestInterface(url, param, (res) => {
					if (res.code == 200) {
						Dialog.alert({
							title: '提示',
							message: res.msg
						}).then(() => {
							this.$router.go(-1)
						})
					}
				})
            },
            eventClickOrderOut() {
                // window.sessionStorage.setItem('outOrder', this.ibase.number);
                // console.log(this.ibase);
                this.$router.push({
                    path: '/reservoirManagement/stock-out',
                    query: {
                        order: this.ibase.number,
                        garbageid: this.ibase.oda.detail[0].garbageid,
                        id: this.ibase.oda.id
                    }
                });
            }
		}
	}
</script>

<style lang="scss" scoped>
	.order-list-container {
		border-bottom: 0.4rem solid #eeeeee;

		.olc-head {
			margin-bottom: 1rem;
			padding: 0.5rem 0rem 0.8rem;
			border-bottom: 0.1rem solid #eeeeee;
			display: flex;
			justify-content: space-between;

			span:first-child {
				font-size: 1.3rem;
				color: #999999;
			}

			span:last-child {
				font-size: 1.3rem;
				color: #00cc00;
			}
		}

		.olc-price {
			padding: 1rem 0rem 0rem;
			text-align: right;

			p:first-child {
				font-size: 1.4rem;
				color: #999999;

				span {
					color: #ff0101;
				}

				span:first-child {
					font-size: 1.4rem;
				}

				span:last-child {
					font-size: 1.9rem;
				}
			}

			.tip-footer {
				font-size: 1.3rem;
				color: #ff9000;
			}
		}

		.olc-footer,
		.olc-footer-qun {
			margin-top: 1rem;
			padding: 1rem 0rem;
			border-top: 0.1rem solid #eeeeee;
			display: flex;
			flex-direction: row-reverse;
		}

		.olc-footer-qun {
			margin: 0rem;
			padding-top: 0.5rem;
			border: none;
		}
	}

	.order-assist-button {
		background-color: #ffffff;
		color: #00cc00 !important;
		padding-left: 2rem !important;
		padding-right: 2rem !important;
		font-size: 1.3rem;
		margin-right: 0.8rem;
	}
</style>
